function dosearchcity(xAwal) {
    xSearch = "";
    try
    {
        if ($("#edSearch").val() != "") {
            xSearch = $("#edSearch").val();
        }
    } catch (err) {
        xSearch = "";
    }
    if (typeof (xSearch) == "undefined") {
        xSearch = "";
    }
    $(document).ready(function() {
        $.ajax({
            url: getBaseURL() + "index.php/ctrcity/searchcity/",
            data: "xAwal=" + xAwal + "&xidstate=" + $("#edidstate").val() + "&xSearch=" + xSearch,
            cache: false,
            dataType: 'json',
            type: 'POST',
            success: function(json) {
                $("#tabledatacity").html(json.tabledatacity);
            },
            error: function(xmlHttpRequest, textStatus, errorThrown) {
                alert("Error juga" + xmlHttpRequest.responseText);
            }
        });
    });
}

function doeditcity(edidx) {
    $(document).ready(function() {
        $.ajax({
            url: getBaseURL() + "index.php/ctrcity/editreccity/",
            data: "edidx=" + edidx,
            cache: false,
            dataType: 'json',
            type: 'POST',
            success: function(json) {
                $("#edidx").val(json.idx);
                $("#edidstate").val(json.idstate);
                $("#edcity").val(json.city);
                $("#edcode").val(json.code);
                $("#eddatein").val(json.datein);
                $("#edidpegawai").val(json.idpegawai);
            },
            error: function(xmlHttpRequest, textStatus, errorThrown) {
                alert("Error juga " + xmlHttpRequest.responseText);
            }
        });
    });
}

function doClearcity() {
    $(document).ready(function() {
        $("#edidx").val("0");
//        $("#edidstate").val("");
        $("#edcity").val("");
        $("#edcode").val("");
        $("#eddatein").val("");
        $("#edidpegawai").val("");
    });
}

function dosimpancity() {
    $(document).ready(function() {
        $.ajax({
            url: getBaseURL() + "index.php/ctrcity/simpancity/",
            data: "edidx=" + $("#edidx").val() + "&edidstate=" + $("#edidstate").val() + "&edcity=" + $("#edcity").val() + "&edcode=" + $("#edcode").val() + "&eddatein=" + $("#eddatein").val() + "&edidpegawai=" + $("#edidpegawai").val(),
            cache: false,
            dataType: 'json',
            type: 'POST',
            success: function(msg) {
                doClearcity();
                dosearchcity('-99');
                alert("Data Berhasil Disimpan.... ");
            },
            error: function(xmlHttpRequest, textStatus, errorThrown) {
                alert("Error juga " + xmlHttpRequest.responseText);
            }
        });
    });
}

function dohapuscity(edidx, edidstate) {
    if (confirm("Anda yakin Akan menghapus data " + edidstate + "?"))
    {
        $(document).ready(function() {
            $.ajax({
                url: getBaseURL() + "index.php/ctrcity/deletetablecity/",
                data: "edidx=" + edidx,
                cache: false,
                dataType: 'json',
                type: 'POST',
                success: function(json) {
                    doClearcity();
                    dosearchcity('-99');
                },
                error: function(xmlHttpRequest, textStatus, errorThrown) {
                    alert("Error juga " + xmlHttpRequest.responseText);
                }
            });
        });
    }
}


dosearchcity(0);


